package net.poddubnyak.friendlist.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.poddubnyak.friendlist.dao.UserDAO;
import net.poddubnyak.friendlist.domain.User;

/**
 * UserService class represents Service for User class.
 * 
 * @author Poddubnjak Petr
 */
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDAO userDAO;

	/**
	 * Add User object
	 * 
	 * @param user
	 */
	@Transactional
	public void addUser(User user) {
		userDAO.addUser(user);
	}

	/**
	 * Delete User object
	 * 
	 * @param id
	 *            - id of user
	 */
	@Transactional
	public void removeUser(Integer id) {
		userDAO.removeUser(id);
	}

	/**
	 * Update User object
	 * 
	 * @param user
	 *            - wich needed to update
	 */
	@Transactional
	public void updateUser(User user) {
		userDAO.updateUser(user);
	}

	/**
	 * Get list of all User objects
	 * 
	 * @return - list of all users
	 */
	@Transactional
	public List<User> listUser() {
		return userDAO.listUser();
	}

	/**
	 * Get list of 5 User objects with max. rating variables
	 * 
	 * @return - list of 5 toprated User objects.
	 */
	@Transactional
	public List<User> listTopUsers() {
		return userDAO.listTopUsers();
	}

	/**
	 * Get list of User objects with similar groupId variables
	 * 
	 * @param groupId
	 *            - id of group
	 * @return - list of classmates User objects
	 */
	@Transactional
	public List<User> listClassmates(String groupId) {
		return userDAO.listClassmates(groupId);
	}

	/**
	 * Gets User object with some id variable
	 * 
	 * @param id
	 *            - id of User object
	 * @return - User object
	 */
	@Transactional
	public User getUserById(Integer id) {
		return userDAO.getUserById(id);
	}

	/**
	 * Gets User object by email variable
	 * 
	 * @param email
	 *            - addres of users email
	 * @return - User object
	 */
	@Transactional
	public User getUserByEmail(String email) {
		return userDAO.getUserByEmail(email);
	}

}
